package com.yoso.springcloud.controller;

import com.yoso.springcloud.service.PaymentHystrixService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author shizejin
 * @date 2021/10/19
 * @description:
 */
@RestController
/*@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")//全局的兜底方法*/
public class OrderHystrixController {
    @Resource
    private PaymentHystrixService paymentHystrixService;

/*    @HystrixCommand(fallbackMethod = "payment_TimeoutHandler",commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "4000")})//4秒钟以内是正常的业务逻辑*/
    /*这种方式冗杂耦合，每一个方法都要配置一个兜底方法*/

//    @HystrixCommand
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        return paymentHystrixService.paymentInfo_TimeOut(id);
    }

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        return paymentHystrixService.paymentInfo_OK(id);
    }


    /**
     * 兜底方法的返回值和参数类型要与业务方法一致
     */
/*    public String payment_TimeoutHandler(Integer id){
        return "线程：" + Thread.currentThread().getName() + "payment_TimeoutHandler,系统繁忙，请稍后再试\t0(ππ)0";
    }*/

    /**
     * 全局的兜底方法
     */
/*    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试。";
    }*/
}
